/*
 * @Author: 米亚流年 miyaliunian@gmail.com
 * @Date: 2024-02-20 14:13:59
 * @LastEditors: 米亚流年 miyaliunian@gmail.com
 * @LastEditTime: 2024-02-20 14:59:22
 * @FilePath: /Component-Gallery/docs/plugins/index.js
 * @Description: 这是默认设置,请设置`customMade`, 打开koroFileHeader查看配置 进行设置: https://github.com/OBKoro1/koro1FileHeader/wiki/%E9%85%8D%E7%BD%AE
 */
import vue from '@vitejs/plugin-vue'
import Inspect from 'vite-plugin-inspect'
import vueJsx from '@vitejs/plugin-vue-jsx'
import Components from 'unplugin-vue-components/vite'
import { NaiveUiResolver } from 'unplugin-vue-components/resolvers'
import transformedVueSrc from './transformed-vue-src'

const fileRegex = /\.(md|vue)$/

const createMyPlugin = () => {
  const myPlugin = {
    name: 'vite-md-parse',
    transform(code, id) {
      if (fileRegex.test(id)) {
        return transformedVueSrc(code, id)
      }
    }
  }
  return [
    myPlugin,
    vue({ include: [/\.vue$/, /\.md$/] }),
    vueJsx(),
    Components({
      include: [/\.vue$/, /\.md$/],
      resolvers: [NaiveUiResolver()]
    }),
    Inspect()
  ]
}

export default createMyPlugin
